import axios from "axios";
// import { access } from "fs";
var service = axios.create(
    {
        baseURL: 'http://180.76.99.14/api',/*'http://180.76.99.14/api',*/ //http://118.178.238.19:3001/api
        
        timeout: 6 * 1000,
        
    }
)

//请求拦截器
service.interceptors.request.use(
    (config) => {
        localStorage.getItem('token') && (config.headers.token = localStorage.getItem('token'))
        return config
    },
    (err) => {
return Promise.reject(err)
    }
)
//响应拦截器
service.interceptors.response.use(
    (res)=>{
        return res
    },
    (err)=>{
        console.log(err);
        if (err.response.status === 401) {
            alert('身份验证失败,登陆过期,请重新登录');
        }
        else if (err.response.status === 404) {
            alert('访问路径有误!');
        }
        else if (err.response.status === 500) {
            alert('服务器内部错误!');
        }
        return Promise.reject(err)
    }
)
export default service